//
//  U_UserDefaults.m
//  s.
//
//  Created by pro on 2021/1/19.
//  Copyright © 2021 hailuo. All rights reserved.
//

#import "U_UserDefaults.h"

@implementation U_UserDefaults
#pragma mark - DriverModel

/* 清空DriverModel **/
+(void)removeUserModel {
    NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
    NSString *path = [docPath stringByAppendingPathComponent:@"Upay.saveUserModel"];
    if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
        NSError *error = nil;
        [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
        if (error) {
            NSLog(@"清除用户信息失败");
        } else {
            NSLog(@"清除用户信息成功");
        }
     }
}




+(void)savePayPassword:(NSString *)unit{
    [[NSUserDefaults standardUserDefaults] setObject:unit forKey:@"U.paypassword"];
}
+(NSString *)fetchPayPassword {
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"U.paypassword"];;
}

+(void)saveFaceIDOpen:(NSString *)unit {
    [[NSUserDefaults standardUserDefaults] setObject:unit forKey:@"U.faceid"];
}
+(BOOL)fetchFaceIDOpen {
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"U.faceid"];;
}

+(void)saveSetFaceID:(NSString *)unit {
    [[NSUserDefaults standardUserDefaults] setObject:unit forKey:@"U.setfaceid"];
}
+(BOOL)fetchSetFaceID {
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"U.setfaceid"];;
}

/* 保存时间间隔 */
+(void)saveToken:(NSString *)IntervalNum
{
    [[NSUserDefaults standardUserDefaults] setObject:IntervalNum forKey:@"U.token"];
}
/* 取出时间间隔 */
+(NSString *)fetchToken;
{
    return [[NSUserDefaults standardUserDefaults] objectForKey:@"U.token"];;
}

+(void)saveLanguage:(NSString *)language{
    [[NSUserDefaults standardUserDefaults] setObject:language forKey:@"U.language"];

}
+(NSString *)fetchLanguage {
    NSString * lang = [[NSUserDefaults standardUserDefaults] objectForKey:@"U.language"];
   
    return lang?lang:@"2";
}

//+(void)saveUnit:(NSString *)unit {
//    [[NSUserDefaults standardUserDefaults] setObject:unit forKey:@"U.unit"];
//}
//+(NSString *)fetchUnit{
//    return [[NSUserDefaults standardUserDefaults] objectForKey:@"U.unit"];;
//}
+ (BOOL)fetchVip{
    return [[[NSUserDefaults standardUserDefaults] objectForKey:@"UPay.vip"] boolValue];
}

+ (void)clearLocalInfo {
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"U.token"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"UPay.vip"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"U.unit"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"U.language"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"U.setfaceid"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"U.faceid"];
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"U.paypassword"];
    [U_UserDefaults removeUserModel];
    [U_UserDefaults removeUserBalance];
}

#pragma mark - ConfigDic
+(void)saveConfigDic:(NSDictionary *)configDic;
{

    [[NSUserDefaults standardUserDefaults] setObject:[configDic mj_JSONData] forKey:@"shop.saveConfigDic"];
}

+(NSDictionary *)fetchConfigDic;
{
    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"shop.saveConfigDic"];
    NSDictionary *configDic = [data mj_JSONObject];
    return configDic;
}


@end
